package com.example.a10928.weifriend.ui.personal_center

import android.content.Intent
import android.graphics.Color
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.widget.LinearLayoutManager
import android.text.TextUtils
import com.example.a10928.weifriend.App
import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.adapter.MemberAdapter
import com.example.a10928.weifriend.adapter.MyTeamAdapter
import com.example.a10928.weifriend.http.api.VariableName
import com.example.a10928.weifriend.http.api.base.MemberDetailBean
import com.example.a10928.weifriend.ui.BaseActivity
import com.example.a10928.weifriend.util.RxUtil
import com.example.a10928.weifriend.util.StatusBarUtil
import com.githang.statusbar.StatusBarCompat
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_member.*
import java.util.ArrayList

class MemberActivity : BaseActivity() {


    var type:String=""
    var datas:MutableList<MemberDetailBean.UsersBean>?= mutableListOf()
    var adapter:MemberAdapter?=null

    override fun getContentView(): Int {
        return R.layout.activity_member
    }

    override fun initView() {
        StatusBarCompat.setStatusBarColor(this, Color.WHITE,true)
        type=intent.getStringExtra(VariableName.TYPE)

        when(type){
            "1"->{
                layout_title.setTitle("普通会员")
            }
            "2"->{

            }
        }

        supportActionBar?.hide()

        var twoType=intent.getStringExtra(VariableName.TWOTYPE)
        if(twoType.equals("0")){
            App.app().bpService.getClass1Details(App.app().user.userId,type)
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                adapter = MemberAdapter(R.layout.item_team, datas,twoType,type)
                                recyc.setLayoutManager(LinearLayoutManager(this))
                                recyc.setAdapter(adapter)

                                adapter?.setOnItemClickListener { adapter, view, position ->

                                }

                                datas?.addAll(it.data.users)
                                adapter?.notifyDataSetChanged()
                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )
        }else{
            App.app().bpService.getClass2Details(App.app().user.userId,type)
                    .compose(RxUtil.io2mainLoad(this))
                    .subscribe(
                            Consumer {
                                adapter = MemberAdapter(R.layout.item_team, datas,twoType,type)
                                recyc.setLayoutManager(LinearLayoutManager(this))
                                recyc.setAdapter(adapter)

                                adapter?.setOnItemClickListener { adapter, view, position ->

                                }

                                datas?.addAll(it.data.users)
                                adapter?.notifyDataSetChanged()
                            },
                            Consumer {
                                RxUtil.errorException(it)
                            }
                    )
        }






    }

    override fun initData() {

    }


}
